import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    //给定一个有序整型数组, 实现二分查找
    public static int search1(int[] arrays,int num){
        int left = 0;
        int right = arrays.length;
        int mid;
        while(left<right){
            mid = (left+right)/2;
            if(arrays[mid]<num){
                left = mid;
                left++;
            }else if(arrays[mid]>right){
                right = mid;
                right++;
            }else{
                return mid;
            }
        }
        return -1;
    }
    public static void main1(String[] args) {
        int[] arrays = {1,2,3,4,5,6,7,8,9};
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt() ;
        System.out.println(search1(arrays,num));
    }

    public static boolean JugeRight(int[] array){
        int left = 0;
        int i = 0;
        while(left<array.length){
            if(left>array[i]){
                return false;
            }else{
                i++;
                left++;
            }
        }
        return true;
    }
    public static void main2(String[] args) {
        int[] array1 = {1,2,3,4,5,6,7,8,9};
        int[] array2 = { 1,2,3,4,5,6,8,7,9,0};
        System.out.println(JugeRight(array1));
        System.out.println(JugeRight(array2));
    }

    public static void bubblesort(int[] array){
        int i = 0;
        int j = 0;
        for(i = 0;i<array.length;i++){
            boolean sort = false;
            for(j = 1;j<array.length-i;j++) {
                if (array[j] < array[j - 1]) {
                    int tem = array[j];
                    array[j] = array[j - 1];
                    array[j - 1] = tem;
                    sort = true;
                }
            }
            if(sort==false){
                return;
            }
        }
    }
    public static void main3(String[] args) {
        int[] array = {9,8,7,6,5,4,3,2,1};
        bubblesort(array);
        System.out.println(Arrays.toString(array));
    }
    //给定一个非空整数数组，除了某个元素只出现一次以外，其余每个元素均出现两次。找出那个只出现了一次的元素。
    public static int search(int[] array){
        int n = 0;
        int i = 0;
        boolean count = true;
        while(n<array.length){
            int num = array[n];
            for(i =0;i<array.length;i++){
                count = true;
                if(num==array[i]&&n!=i){
                    n++;
                    count = false;
                    break;
                }
            }
            if(count==true){
                return n;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        int[] array = {6,66,66,6,1};
        int num = search(array);
        System.out.println(array[num]);
    }
}
